package com.launch.carmanager.common.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;

public class CMViewPager extends ViewPager {

    private boolean paging = false;

    public CMViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * disable smoothly scroll
     */
    @Override
    public void setCurrentItem(int item) {
        super.setCurrentItem(item, false);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return this.paging && super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return this.paging && super.onInterceptTouchEvent(event);
    }

    @Override
    public boolean executeKeyEvent(KeyEvent event) {
        return this.paging && super.executeKeyEvent(event);
    }

    /**
     * Enable or disable navigation
     */
    public void setPagingEnabled(boolean paging) {
        this.paging = paging;
    }


}
